﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gzh.DAL.Models.Mapping
{
    /// <summary>
    /// ${table.comment}
    /// </summary>
    public class ${TableName}Map : EntityTypeConfiguration<${TableName}>
    {
        public ${TableName}Map()
        {
       <#list table.columns  as column>
       <#if column.columnKey=='true'>
           // Primary Key
           this.HasKey(t => t.${column.columnName});
           // Properties
           this.Property(t => t.id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

        <#elseif column.isRequired =='true' && column.columnType =='String'>
           this.Property(t => t.${column.columnName})
               .IsRequired()
               .HasMaxLength(${column.columnSize});
        <#elseif column.columnType =='String' && column.isRequired =='false'>
           this.Property(t => t.${column.columnName})
               .HasMaxLength(${column.columnSize});
        <#elseif column.isRequired =='true'&& column.columnType !='String'>
           this.Property(t => t.${column.columnName})
               .IsRequired();
       </#if>
        </#list>

           // Table & Column Mappings
           this.ToTable("${TableName}");
        <#list table.columns  as column>
           this.Property(t => t.${column.columnName}).HasColumnName("${column.columnName}");
        </#list>
        }
    }
}
